home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 7 #1 / IMG Vol 7-1.iso / Updaters / InputSprocket 1.3 / Sample Drivers / ISp Sample ADB Sources / ISpSampleADB.h < prev    next >
Text File  |  1998-04-15  |  6KB  |  280 lines

  1. /*************************************************************************************
  2.  
  3. File:      ISpSampleADB.h
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17.  
  18. #ifndef __ISPSAMPLEADB__
  19. #define __ISPSAMPLEADB__
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24.  
  25. #ifndef __DESKBUS__
  26. #include <DeskBus.h>
  27. #endif
  28.  
  29. #ifndef __FILES__
  30. #include <Files.h>
  31. #endif
  32.  
  33. #ifndef __INPUTSPROCKET__
  34. #include <InputSprocket.h>
  35. #endif
  36.  
  37. #include "ISpPlugInUI.h"
  38. #include "InputSprocketDefer.h"
  39. #include "ISpSampleADBRes.h"
  40.  
  41. class SidewinderPro : public ISpPlugInUI
  42. {
  43.     public:
  44.         SidewinderPro(ADBAddress inADBAddr, const FSSpec &inFileSpec);
  45.         ~SidewinderPro();
  46.         
  47.         
  48.     public:
  49.         // these must be overridden in the subclass
  50.         OSStatus Init(    UInt32 count, 
  51.                                 ISpNeed needs[], 
  52.                                 ISpElementReference virtualElements[],
  53.                                 Boolean used[],
  54.                                 OSType appCreatorCode,
  55.                                 OSType subCreatorCode, 
  56.                                 UInt32 reserved,
  57.                                 void* reserved2);
  58.         OSStatus Stop(void);
  59.         OSStatus GetSize(Point &minimum, Point &best);
  60.         OSStatus HandleEvent(EventRecord &theEvent, Boolean &handled);
  61.         OSStatus Show(DialogPtr theDialog, short dialogItemNumber, Rect &r);
  62.         OSStatus Hide(void);
  63.         OSStatus BeginConfiguration(UInt32 count, ISpNeed needs[]);
  64.         OSStatus EndConfiguration(Boolean accept);
  65.         OSStatus GetIcon(short &iconSuiteResourceId);
  66.         OSStatus GetState(UInt32 buflen, void *buffer, UInt32 &length);
  67.         OSStatus SetState(UInt32 length, void *buffer);
  68.         OSStatus SetActive(Boolean active);
  69.         OSStatus DialogItemHit(short itemHit);    
  70.  
  71.         OSStatus Tickle(void);
  72.         OSStatus InterruptTickle(void);
  73.         OSStatus Draw(void);
  74.         OSStatus Click(const EventRecord &event);
  75.         
  76.         OSStatus ADBReInit(Boolean inPostProcess);
  77.  
  78.     public:
  79.         static OSStatus Initialize(FSSpec fileSpec);
  80.         static Boolean    IsSideWinder(short inDeviceTableIndex);
  81.         static void Terminate(void);
  82.         
  83.         void AutoConfigure(Boolean used[]);
  84.             
  85.     private:
  86.         static SidewinderPro *gSidewinders[16];
  87.         
  88.     private:
  89.         OSStatus CreateDevice(void);
  90.         OSStatus DisposeDevice(void);
  91.         
  92.         OSStatus Patch(void);
  93.         OSStatus Unpatch(void);
  94.  
  95.     public:
  96.         void ParseData(
  97.             void                    *inBuffer,
  98.             UInt32                    inCommand);
  99.  
  100.     public:
  101.         
  102.         // virtual element code
  103.         void StartVirtualElements(void);
  104.         void StopVirtualElements(void);
  105.  
  106.         UInt32 * GetDialogItemToNeedMapping () { return mDialogItemToNeedMapping; };
  107.     
  108.     private:
  109.         UInt32     mDialogItemToNeedMapping[kDialogItem_NumPopups+1];    // we dont use index 0
  110.     
  111.  
  112.     public:
  113.         enum
  114.         {
  115.             kTrigger = 0,
  116.             kTopButton,
  117.             kStickHighButton,
  118.             kStickLowButton,
  119.             kBaseFarLeft,
  120.             kBaseFarRight,
  121.             kBaseNearLeft,
  122.             kBaseNearRight,
  123.             kNumSidewinderButtons
  124.         };
  125.     
  126.     private:
  127.         typedef struct
  128.         {
  129.             UInt32 xAxis;
  130.             UInt32 yAxis;
  131.             UInt32 throttle;
  132.             UInt32 rudder;
  133.             UInt32 hat;
  134.             UInt32 buttons[kNumSidewinderButtons];
  135.         } SidewinderStateStruct;
  136.  
  137.         typedef struct
  138.         {
  139.             // axis
  140.             UInt32 xAxis;
  141.             UInt32 yAxis;
  142.             UInt32 throttle;
  143.             UInt32 rudder;
  144.             UInt32 xAxis_as_buttons[2];
  145.             UInt32 yAxis_as_buttons[2];
  146.             UInt32 throttle_as_buttons[2];
  147.             UInt32 rudder_as_buttons[2];
  148.             
  149.             // hat
  150.             UInt32 hat;
  151.             UInt32 hat_as_buttons[4]; // t,l,b,r
  152.             UInt32 hat_as_axis[2]; // x,y 
  153.             
  154.             // buttons
  155.             UInt32 buttons[kNumSidewinderButtons];
  156.         } HighLevelData;
  157.  
  158.         SidewinderStateStruct mOldState;
  159.         HighLevelData mOldHLData;
  160.  
  161.         // this function looks at mOldState to set some things up
  162.         #if !__MWERKS__
  163.         inline 
  164.         #endif
  165.         void StateToHighLevelData(const SidewinderStateStruct &inState, HighLevelData& outHLData);
  166.         void SetAsFields(HighLevelData ¤t);
  167.         void PushDataToVirtuals(HighLevelData ¤t);
  168.         
  169.         // reverse
  170.         Boolean mReverseStickVertical;
  171.         Boolean mReverseHatVertical;
  172.         Boolean mReverseRudder;
  173.         Boolean mReverseThrottle;
  174.         
  175.     private:
  176.         short mWhichDevice;
  177.  
  178.         // actual elements, nil if doesn't exist
  179.         ISpDeviceReference mDevice;
  180.         
  181.         ISpElementReference mXAxis;
  182.         ISpElementReference mYAxis;
  183.         ISpElementReference mThrottle;
  184.         ISpElementReference mRudder;
  185.  
  186.         ISpElementReference mHat;
  187.         
  188.         ISpElementReference mButtons[kNumSidewinderButtons];
  189.  
  190.     private:
  191.     // ui code, internal
  192.     // internal
  193.     Boolean mVisable;    
  194.     Boolean mActive;
  195.     volatile Boolean mVirtualElementsValid;
  196.     
  197.     void SetVirtualElements(void);
  198.     Boolean IsPressed (short inDialogItem);    // is this dialog item 'pressed' (ie on the device)
  199.     
  200.     Boolean mPopupPressed[kDialogItem_NumPopups];
  201.     
  202.     void UpdateSingleButton(UInt32 curButton, UInt32 index);
  203.     void UpdateAllButtons(void);
  204.  
  205.     private:
  206.     
  207.     typedef struct
  208.     {
  209.         // axis
  210.         ISpElementReference xAxis;
  211.         ISpElementReference yAxis;
  212.         ISpElementReference throttle;
  213.         ISpElementReference rudder;
  214.         
  215.         ISpElementReference stickMovement;
  216.         ISpElementReference stickDPad;
  217.         
  218.         ISpElementReference xAxis_as_buttons[2];
  219.         ISpElementReference yAxis_as_buttons[2];
  220.         ISpElementReference throttle_as_buttons[2];
  221.         ISpElementReference rudder_as_buttons[2];
  222.         
  223.         // hat
  224.         ISpElementReference hat;
  225.         ISpElementReference hat_as_movement;
  226.         ISpElementReference hat_as_buttons[4]; // t,l,b,r
  227.         ISpElementReference hat_as_axis[2]; // x,y 
  228.         
  229.         // buttons
  230.         ISpElementReference buttons[kNumSidewinderButtons];
  231.     } VirtualElements;
  232.     
  233.     
  234.     VirtualElements mVirtuals;
  235.     
  236. private:
  237.     void ClearVirtuals (void);
  238.         
  239.     OSStatus PushAllNonDefaultValues(void);
  240.         
  241. private:
  242.     FSSpec mFileSpec;
  243.     Rect mRect;
  244.     short mResRef;
  245.     
  246.     typedef struct
  247.     {
  248.         UInt32 version;
  249.         
  250.         UInt32 mapping[kDialogItem_NumPopups];        
  251.  
  252.         UInt32 flags;
  253.     } MicrosoftSetVersion1;
  254.  
  255.     enum
  256.     {
  257.         kSetReverseStickVertical    =    0x00000001,
  258.         kSetReverseHatVertical        =    0x00000002,
  259.         kSetReverseThrottle         =    0x00000004,
  260.         kSetReverseRudder             =    0x00000008
  261.     };
  262.  
  263.     enum 
  264.     {
  265.         kSetVersion1 = '0002'
  266.     };
  267.  
  268. private:
  269.     Boolean                        mOrphan;
  270.     ADBAddress                    mADBAddress;
  271.     Boolean                        mMustRestorePatch;
  272.     Boolean                        mPatched;
  273.     ISpADBDeferRef                mADBDefer;
  274.  
  275. private:
  276.     void DoReverse(short dialog_item, Boolean &the_boolean);
  277.  
  278. };
  279.  
  280. #endif // SAMPLEADB